package cn.gjxblog.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.social.security.SocialUser;
import org.springframework.social.security.SocialUserDetails;
import org.springframework.social.security.SocialUserDetailsService;
import org.springframework.stereotype.Component;



/**
 * @author gjx
 * @version v1.0
 * @Description
 * @date 2019/1/15 17:13
 */

@Component
public class MyUserDetailService implements UserDetailsService,SocialUserDetailsService {
    private Logger logger = LoggerFactory.getLogger(MyUserDetailService.class);

    @Autowired
    private PasswordEncoder passwordEncoder;

    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {


        //TODO:根据用户查询用户信息
        String encode = passwordEncoder.encode("123456");
        logger.info("登录用户名:"+s+"===="+"密码为:"+encode);
        return new User(s,encode,AuthorityUtils.commaSeparatedStringToAuthorityList("admin"));
    }

    @Override
    public SocialUserDetails loadUserByUserId(String s) throws UsernameNotFoundException {
        //TODO:根据用户查询用户信息
        String encode = passwordEncoder.encode("123456");
        logger.info("登录用户名:"+s+"===="+"密码为:"+encode);
        return new SocialUser(s,encode,AuthorityUtils.commaSeparatedStringToAuthorityList("admin"));
    }
}
